package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.bo.WxGoodsListBO;
import com.cskaoyan.bean.pojo.MallGoods;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.service.WxCategoryService;
import com.cskaoyan.service.WxGoodsService;
import com.cskaoyan.util.CurrentUesr;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Fengyi
 * @description: wx商品
 * @time: 2021/7/12 10:10
 */
@RequestMapping("wx/goods")
@RestController
public class WxGoodsController {

    @Autowired
    WxGoodsService wxGoodsService;
    @Autowired
    WxCategoryService wxCategoryService;


    @RequestMapping("count")
    public BaseRespVo goodsCount() {
        WxGoodsCountVO wxGoodsCountVO = new WxGoodsCountVO();
        wxGoodsCountVO.setGoodsCount(wxGoodsService.queryGoodsCount());
        return BaseRespVo.ok(wxGoodsCountVO);
    }

    @RequestMapping("category")
    public BaseRespVo getCategory(Integer id) {
        WxCategoryVO wxCategoryVO = wxCategoryService.selectCategory(id);
        return BaseRespVo.ok(wxCategoryVO);
    }

    @RequestMapping("list")
    public BaseRespVo goodsList(WxGoodsListBO wxGoodsListBO) {
        wxGoodsListBO.setLimit(wxGoodsListBO.getSize());
        List<MallGoods> mallGoodsList = wxGoodsService.queryGoodsList(wxGoodsListBO);
        WxGoodsListVO wxGoodsListVO = new WxGoodsListVO();
        wxGoodsListVO.setGoodsList(mallGoodsList);
        return BaseRespVo.ok(wxGoodsListVO);
    }


    @RequestMapping("detail")
    public BaseRespVo goodsDetail(Integer id) {

        Subject subject = SecurityUtils.getSubject();
        if(subject.getPrincipals() != null) {
            int userId = CurrentUesr.getUserId();

            int insert = wxGoodsService.insertFootprint(id,userId);
        }

        WxGoodsDetailVO wxGoodsDetailVO = wxGoodsService.queryGoodsDetail(id);
        return BaseRespVo.ok(wxGoodsDetailVO);
    }

    @RequestMapping("related")
    public BaseRespVo relatedGoods(Integer id) {
      WxGoodsListVO wxGoodsListVO = wxGoodsService.queryRelatedGoodsList(id);
      return BaseRespVo.ok(wxGoodsListVO);
    }

}


